<template>
  <div class="loading-spinner" :class="{ 'full-screen': fullScreen }">
    <div class="spinner-container">
      <div class="spinner" :style="spinnerStyle">
        <div class="spinner-inner"></div>
      </div>
      <p v-if="text" class="loading-text">{{ text }}</p>
    </div>
  </div>
</template>

<script>
export default {
  name: 'LoadingSpinner',
  
  props: {
    // 是否全屏显示
    fullScreen: {
      type: Boolean,
      default: false
    },
    
    // 加载文本
    text: {
      type: String,
      default: ''
    },
    
    // 大小
    size: {
      type: String,
      default: 'medium',
      validator: value => ['small', 'medium', 'large'].includes(value)
    },
    
    // 颜色
    color: {
      type: String,
      default: '#409eff'
    }
  },
  
  computed: {
    spinnerStyle() {
      const sizes = {
        small: '20px',
        medium: '40px',
        large: '60px'
      }
      
      return {
        width: sizes[this.size],
        height: sizes[this.size],
        borderTopColor: this.color
      }
    }
  }
}
</script>

<style lang="scss" scoped>
.loading-spinner {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  
  &.full-screen {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(255, 255, 255, 0.9);
    z-index: 9999;
  }
}

.spinner-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}

.spinner {
  border: 3px solid #f3f3f3;
  border-top: 3px solid #409eff;
  border-radius: 50%;
  animation: spin 1s linear infinite;
  
  .spinner-inner {
    width: 100%;
    height: 100%;
  }
}

.loading-text {
  margin: 0;
  color: #606266;
  font-size: 14px;
  text-align: center;
}

@keyframes spin {
  0% { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}
</style>